﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace INTROSE
{
    public partial class View_User : Form
    {
        SqlConnection con = new SqlConnection("Data Source = .\\SQLEXPRESS; Database = Introse; Integrated Security = True");
        private string name, position;
        public View_User(string name, string position, string view)
        {
            InitializeComponent();
            this.name = name;
            this.position = position;
            if (position == "factory worker")
            {
                con.Open();
                SqlCommand command = new SqlCommand("SELECT * FROM users WHERE userName='" + view + "'", con);
                SqlDataReader reader = command.ExecuteReader();
                reader.Read();
                txtUsername.Text = reader.GetString(1);
                comboPos.Text = reader.GetString(3);
                txtName.Text = reader.GetString(4);
                txtAdd.Text = reader.GetString(5);
                try
                {
                    txtEAdd.Text = reader.GetString(6);
                }
                catch { ArgumentNullException e; }
                con.Close();
            }
            else
            {
                con.Open();
                SqlCommand command = new SqlCommand("SELECT * FROM users WHERE uName='" + view + "'", con);
                SqlDataReader reader = command.ExecuteReader();
                reader.Read();
                txtUsername.Text = reader.GetString(1);
                comboPos.Text = reader.GetString(3);
                txtName.Text = reader.GetString(4);
                txtAdd.Text = reader.GetString(5);
                try
                {
                    txtEAdd.Text = reader.GetString(6);
                }
                catch { ArgumentNullException e; }
                con.Close();
            }
        }

        private void View_User_Load(object sender, EventArgs e)
        {
            txtAdd.Enabled = false;
            txtEAdd.Enabled = false;
            txtName.Enabled = false;
            txtUsername.Enabled = false;
            comboPos.Enabled = false;
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            if (this.position == "factory worker")
            {
                this.Close();
                MenuProductionStaff menu = new MenuProductionStaff(name, position);
                menu.Show();
            }
            else
            {
                this.Close();
                View_Users_Tabbed view = new View_Users_Tabbed(name, position);
                view.Show();
            }
        }
    }
}
